Xbasic

*months_between Function

Syntax

dim Result as N = *MONTHS_BETWEEN(t1 as T, t2 as T)

Arguments

t1Time

A datetime value.

t2Time

A datetime value

Returns

ResultNumeric

Returns the months between two dates or times. If t2 is a date or time later than t1, *MONTHS_BETWEEN will return a negative value.

Description

Return difference of months between two dates or times.

Example

dim cn as sql::Connection
cn.open("::Name::northwind")

dim args as sql::arguments
args.set("orderID",10251)

dim sql as c = "SELECT * FROM orders WHERE orderid = :orderID"
cn.execute(sql,args)

if (cn.ResultSet.NextRow()) then
    dim t1 as T = cn.resultset.data("requireddate")
    dim t2 as T = cn.resultset.data("shippeddate")

    dim months_between as N = *months_between(t1,t2)
    months_between = abs(months_between)
    dim timing as c = ""
    if (t2 > t1) then
        timing = "late"
    else
        timing = "early"
    end if

    ui_msg_box("Months Between","Order 10251 was shipped " + months_between + " month " + timing + crlf(2) + "Required date: " + time("MM/dd/yyyy",t1) + crlf() + "Shipped date: " + time("MM/dd/yyyy", t2))
end if

cn.close()

See Also